<?php

/**
 * The function __autoload includes and creates new instances of static classes.
 * 
 * @author Cesar Augustus Silva <cesaraugustussilva@linuxmail.org>
 * @copyright Copyright (c) 2013, Cesar Augustus Silva
 * @license http://www.gnu.org/licenses/gpl.html GNU GPL v3.0
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <­http://www.gnu.org/licenses/>.
 */
function __autoload($class_name) {
    if (!class_exists($class_name)) {
        $class_name = str_replace(chr(0), '', $class_name);
        $class_dir = dirname(__FILE__).'/../classes/';
        if (substr($class_name, -4) == 'Core')
            require_once($class_dir.substr($class_name, 0, -4).'.php');
        elseif (file_exists($class_dir.$class_name.'.php')) {
            require_once($class_dir.$class_name.'.php');
            $class_info = new ReflectionClass($class_name.((interface_exists($class_name, false) or class_exists($class_name, false)) ? '' : 'Core'));
            if (!$class_info->isInterface() && substr($class_info->name, -4) == 'Core')
                eval(($class_info->isAbstract() ? 'abstract ' : '').'class '.$class_name.' extends '.$class_name.'Core {}');
        }
    }
}